<template>
<table>
    <tr>
        <td>账号</td>
        <td>
            <input type="text" placeholder="请输入账号" v-model="info.T_Name">
        </td>
    </tr>
    <tr>
        <td>密码</td>
        <td>
            <input type="password" placeholder="请输入密码" v-model="info.T_Pwd">
        </td>
    </tr>
    <tr>
        <td>身份证号</td>
        <td>
            <input type="text" placeholder="请输入身份证号" v-model="info.Card">
        </td>
    </tr>
    <tr>
        <td>联系方式</td>
        <td>
            <input type="text" placeholder="请输入联系方式" v-model="info.Phone">
        </td>
    </tr>
    <tr>
        <td>真实姓名</td>
        <td>
            <input type="text" placeholder="请输入真实姓名" v-model="info.T_Tream">
        </td>
    </tr>
    <tr>
        <td>会员类型</td>
        <td>
            <select v-model="info.TY_id">
                <option :value="0">请选择</option>
                <option v-for="init in typeinfo" :value="init.TY_id">{{ init.TY_name }}</option>
            </select>
        </td>
    </tr>
    <tr>
        <td>会员等级</td>
        <td>
            <select v-model="info.D_id">
                <option :value="0">请选择</option>
                <option v-for="inie in dengjiinfo" :value="inie.D_id">{{ inie.D_name }}</option>

            </select>
        </td>
    </tr>
    <tr>
        <td></td>
        <td>
            <input type="button" value="添加" @click="Saveadd">
        </td>
    </tr>
</table>
</template>

<script setup lang="ts">
import {onMounted,ref} from 'vue'
import axios from 'axios'

onMounted(()=>{
MemType();
Memdegji();
})
const typeinfo=ref([{
    TY_id:"",
    TY_name:""
}])
const MemType=()=>{
    axios.get("https://localhost:7281/api/Member/GetallType")
    .then(res=>{
        typeinfo.value=res.data;
    })
}

const dengjiinfo=ref([{
    D_id:"",
    D_name:""
}])
const Memdegji=()=>{
    axios.get("https://localhost:7281/api/Member/GetallDengji")
    .then(res=>{
        dengjiinfo.value=res.data;
    })
}



const info=ref({
     "T_Name": "",
    "T_Pwd": "",
    "Card": "",
    "Phone": "",
    "T_Tream": "",
     "IsMobile": true,
     "TY_id": 0,
     "D_id": 0,
})
//保存
const Saveadd=()=>{
if(info.value.T_Name==""){
    alert('账号不能为空')
}
if(info.value.T_Pwd==""){
    alert('密码不能为空')
}
if(info.value.Card==""){
    alert('身份证不能为空')
}
if(info.value.Phone==""){
    alert('联系方式不能为空')
}
console.log(info.value)
axios.post("https://localhost:7281/api/Member/AddMember",info.value
)
.then(res=>{
    if(res.data>0){
        alert('添加成功')
    }else  if(res.data==-1){
        alert('手机号重复')
    }else{
        alert('添加失败')
    }
}

)
}
console.log(info.value)
</script>

<style scoped>

</style>